<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <script>
        let str = "abcdefg"
        let k = 2
        function solution(str, k) {
            function reverseArr(arr, start, end) {
                while(start < end) {
                    [arr[start], arr[end]] = [arr[end], arr[start]]
                    start++
                    end--
                }
            }

            const arr = Array.from(str)
            reverseArr(arr, 0, k - 1)
            reverseArr(arr, k, arr.length - 1)
            reverseArr(arr, 0, arr.length - 1)
            console.log(arr)
        }

        const res = solution(str, 2)
        console.log(res)

    </script>
</body>
</html>